//
//  YXComposeViewController.swift
//  yanXiangWeiBo
//
//  Created by 颜祥 on 15/12/27.
//  Copyright © 2015年 yanxiang. All rights reserved.
//

import UIKit

class YXComposeViewController: UIViewController
{

    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.orangeColor()
        
        // 1.设置导航条两边的按钮
        setupNavigationBarButton()
        
        // 2.设置底部按钮视图
        setupToolBar()
        
        // 3.设置输入框
        setupTextView()

        
    }
    
    private func setupNavigationBarButton()
    {
        // 取消
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", style: UIBarButtonItemStyle.Plain, target: self, action: "close")
        
        
        // 发送
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "发送", style: UIBarButtonItemStyle.Plain, target: self, action: "send")
        
        // 中间视图
        let prefix = "发微博"
        if let name = YXUserAccount.loadUserAccount()?.screen_name
        {
            // 已经登录
            let text = prefix + "\n" + name
            let label = UILabel()
            label.text = text
            
            label.numberOfLines = 0
            label.font = UIFont.systemFontOfSize(16)
            label.textAlignment = NSTextAlignment.Center
            
            let nameRange = (text as NSString).rangeOfString(name)
            let attar = NSMutableAttributedString(string: text)
            // 设置颜色
            attar.addAttribute(NSForegroundColorAttributeName, value: UIColor.lightGrayColor(), range: nameRange)
            // 设置大小
            attar.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(12), range: nameRange)
            
            // 设置label属性
            label.attributedText = attar
            label.sizeToFit()
            
            navigationItem.titleView = label
            
            
        }else
        {
            // 没有登录
            navigationItem.title = prefix
        }
    }
    
    private func setupToolBar()
    {
        
    }
    
    
    private func setupTextView()
    {
        
    }
    
    private func close()
    {
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    
    

    // MARK: - 懒加载子控件
    private lazy var toolBar: UIToolbar =
    {
        let toolBar = UIToolbar()
        
        // 添加按钮
        
        
        
        
        return toolBar
    }()
  

}
